<template>
	<view class="all-box containers">

		<!-- 404页面 -->
		<view class="noData" v-if="netWorkType == 'none'">
			<noData @handle="refresh"></noData>
		</view>
				<view class="flex-start-box box-item"  >
					<view class="equip-img border-radius4">
						<image src="http://img.aiouning.com/uploader/upload/202212/01/202212010916596388008b68ed8.png" class="publicImg" mode="widthFix"></image>
					</view>
					<view>
						<view class="title  padleft10">
							<text class="over-ellipsis-two">瓯品血糖仪</text>
				
						</view>
					</view>
					<view class="flex-start-box" style="justify-content: flex-end; ">
						<view v-if="data.devList.weitai.mac!=undefined" @tap="cancelBind(5)" class="btn btn-unbind">解绑</view>
						<view v-else-if="data.devList.weitai.mac==undefined" @tap="bind(4)" class="btn  btn-bind">绑定</view>
				
					</view>
				</view>
			 	<view class="flex-start-box box-item"  >
			 		<view class="equip-img border-radius4">
			 			<image src="http://img.aiouning.com/uploader/upload/202110/29/20211029111254617b66b689239.png" class="publicImg" mode="widthFix"></image>
			 		</view>
			 		<view>
			 			<view class="title  padleft10">
			 				<text class="over-ellipsis-two">西恩血压计 LD-871 WIFI</text>

			 			</view>
			 		</view>
					<view class="flex-start-box" style="justify-content: flex-end; ">
						<view v-if="data.devList.pressure.mac!=undefined" @tap="cancelBind(1)" class="btn btn-unbind">解绑</view>
						<view v-else-if="data.devList.pressure.mac==undefined" @tap="bind(1)" class="btn  btn-bind">绑定</view>
						</view>
			 	</view>
				<view class="flex-start-box box-item"  >
					<view class="equip-img border-radius4">
						<image src="http://img.aiouning.com/uploader/upload/202110/29/20211029111257617b66b93e006.png" class="publicImg" mode="widthFix"></image>
					</view>
					<view>
						<view class="title  padleft10">
							<text class="over-ellipsis-two">三诺血糖仪 安稳+Air</text>

						</view>
					</view>
					<view class="flex-start-box" style="justify-content: flex-end; ">
						<view v-if="data.devList.sinocare[3].mac!=undefined || data.devList.sinocare[3].sn!=undefined" @tap="cancelBind(3)" class="btn  btn-unbind">解绑</view>
						<view v-else-if="data.devList.sinocare[3].mac==undefined && data.devList.sinocare[3].sn==undefined" @tap="bind(3)" class="btn  btn-bind" >绑定</view>

					</view>
				</view>
				<view class="flex-start-box box-item"  >
					<view class="equip-img border-radius4">
						<image src="http://img.aiouning.com/uploader/upload/202110/29/20211029111259617b66bbbbfbd.png" class="publicImg" mode="widthFix"></image>
					</view>
					<view>
						<view class="title  padleft10">
							<text class="over-ellipsis-two">三诺血糖尿酸仪 UG-11蓝牙</text>

						</view>
					</view>
					<view class="flex-start-box" style="justify-content: flex-end; ">
						<view v-if="data.devList.sinocare[4].mac!=undefined || data.devList.sinocare[4].sn!=undefined" @tap="cancelBind(4)" class="btn  btn-unbind">解绑</view>
						<view v-else-if="data.devList.sinocare[4].mac==undefined && data.devList.sinocare[4].sn==undefined" @tap="bind(2)" class="btn  btn-bind" >绑定</view>

					</view>
				</view>
				<!-- <view class="flex-start-box box-item"  >
					<view class="equip-img border-radius4">
						<image src="http://img.aiouning.com/uploader/upload/202112/09/2021120909550461b161f8636ae.png" class="publicImg" mode="widthFix"></image>
					</view>
					<view>
						<view class="title  padleft10">
							<text class="over-ellipsis-two">民康血糖仪MK-ZY801蓝牙</text>

						</view>
					</view>
					<view class="flex-start-box" style="justify-content: flex-end; ">
						<view v-if="data.devList.mycuia.mac!=undefined" @tap="cancelBind(2)" class="btn btn-unbind">解绑</view>
						<view v-else-if="data.devList.mycuia.mac==undefined" @tap="bind(3)" class="btn  btn-bind">绑定</view>

					</view>
				</view> -->
				
				
					<!--<view class="flex-start-box box-item"  >
					<view class="equip-img border-radius4">
						<image src="http://img.aiouning.com/uploader/upload/202110/29/20211029111259617b66bbbbfbd.png" class="publicImg" mode="widthFix"></image>
					</view>
					<view>
						<view class="title  padleft10">
							<text class="over-ellipsis-two">体脂称</text>

						</view>
					</view>
					<view class="flex-start-box" style="justify-content: flex-end; ">
						<view v-if="data.devList.sinocare[4].mac!=undefined || data.devList.sinocare[4].sn!=undefined" @tap="cancelBind(4)" class="btn  btn-unbind">解绑</view>
						<view v-else-if="data.devList.sinocare[4].mac==undefined && data.devList.sinocare[4].sn==undefined" @tap="bind(2)" class="btn  btn-bind" >绑定</view>

					</view>
				</view> -->

		<!--解除绑定弹窗 -->
		<uni-popup id="cancelBindPopup" ref="cancelBindPopup" type='center'>
			<view class="self-dialog" style="background: white;">
				<view class="title-bind text-center">
					<text>解除绑定</text>
				</view>
				<view class="content text-center font17">
					是否解除绑定？解绑后无法同步 该设备数据
				</view>
				<view  >
					<view  @tap="confirmCancleBind"  class="btn  btn-bind">确定</view>
				</view>
			</view>
		</uni-popup>

		<!-- 提示弹框 -->
		<tui-tips ref="toast"></tui-tips>

		<uni-popup-vlogin id="popupvLogin" ref="popupvLogin" type="bottom" />
	</view>

</template>

<script>
	// import tuiTag from '@/components/tag/tag'
	// import hxNavbar from '@/components/hx-navbar/hx-navbar'
	import {oss_host} from '@/config/config.js';
	import {
		mapGetters
	} from 'vuex';
	import Vue from 'vue'

	import store from '@/store/index.js';
	export default {


		components: {
			// tuiTag,
			// hxNavbar
		},
		computed: {
			//注册网络状态
			...mapGetters(['netWorkType', 'loginStatus']),
		},

		onShow: function(options) {
			if(this.loginStatus){
				this.getList();
			}
			 // 
		},
		data() {
			return {

				// 图片链接站点
				OSS_HOST: oss_host,
				data: {
				  devList:[]
				},
				type:0
			}
		},
		methods: {
			getList(){
				let _this = this
				var opt = {
					url: '/blutdruck_check/devList',
					success: function(res) {
						if (res.status==1) {
							 _this.data.devList = res.data;
						}
					}
				};
				_this.$service.GetApi(opt)
			},
			confirmCancleBind(){

				let _this = this
				let path = ''
				let data = {}
				if(this.type==1 || this.type==2){
					
					path = '/wifi/unbindDev'
					
					if(this.type==1){
						data = {
							mac:_this.data.devList.pressure.mac,
							factory:_this.data.devList.pressure.factory
						}
					}else{
						data = {
							mac:_this.data.devList.mycuia.mac,
							factory:_this.data.devList.mycuia.factory
						}
					}
					 
				}else if(this.type==5){
					path = '/BlutdruckCheck/unbindWtDev'
					data = {
						mac:_this.data.devList.weitai.mac,
						factory:_this.data.devList.weitai.factory
					}
				}
				else{
					path = '/BlutdruckCheck/unbindDev'

					//血糖
					if(this.type==3){
						let arr = _this.data.devList.sinocare[3];

						data = {
							id:arr.id
						}
					}else{
						//尿酸
						let arr = _this.data.devList.sinocare[4];
						data = {
							id:arr.id
						}
					}

				}
				this.$refs.cancelBindPopup.close()
				let opt = {
					url: path,
					method: 'get',
					data: data,
					success: function(res) {

						if (res.status == 1) {
							_this.getList();
							let options = {
								msg: '解绑成功',
								type: 'green'
							};
							_this.$refs.toast.showTips(options);

						} else {
							let options = {
								msg: '解绑失败',
								type: 'danger'
							};
							_this.$refs.toast.showTips(options);

						}

					}
				};
				if (this.loginStatus) {
					this.$service.GetApi(opt) //网络
				}
			},
			 cancelBind(type){
			 	this.type=type
			 	this.$refs.cancelBindPopup.open()


			 },
			 bind(type){
				 let _this = this
				 let data = {}
				 switch(parseInt(type)){
					 case 1:
						this.$refer.setVilit('/packageHealthy/pages/bind_equip/bind')
						break;
					 case 2:
						//扫码绑定三诺设备
						data.factory = 'scian'
						_this.$refer.setVilit('bind_equip/scan_code_bind');
						break;
					 case 3:
						//民康血糖设备 ?bind_mycuid=1
						data.bind_mycuid=1
						_this.$refer.setVilit('mycuia/index');
						break;
					 case 4:
						data.factory = 'weitai'
						_this.$refer.setVilit('bind_equip/scan_code_bind');
						
						break;
					 break;
				 }

				 let callback = function(url) {
				 	_this.$refs.popupvLogin.open()
				 }
				 _this.$refer.toUrl(callback,data)
			 }
		}
	}
</script>

<style lang="scss">
	@import "./dev_manage";
</style>
